package com.meevle.validators
{
    import mx.validators.Validator;
    import mx.validators.ValidationResult;

    public class PasswordConfirmationValidator extends Validator {

        // Define Array for the return value of doValidation().
        private var results:Array;

        public function PasswordConfirmationValidator () {
            super();
        }

        override protected function doValidation(value:Object):Array {
        
            var password:String = value.password;
            var confirmation:String = value.confirmation; 
            
            // Clear results Array.
            results = [];

            // Call base class doValidation().
            results = super.doValidation(value);        
            // Return if there are errors.
            if (results.length > 0)
                return results;

            // Check first name field. 
            if (password != confirmation) {
                results.push(new ValidationResult(true, 
                    "first", "notIdentical", "Passwords don't match"));
                return results;
            }
            
            return results;
        }
    }
}